/*    
 * Copyright (c) 2013 ISoftStone, Inc.
 * All right reserved.
 *
 * 文件名：      InitializingCronTrigger.java
 * 作者:     Jacky Wang
 * 创建日期： 2013-8-12 下午03:19:41
 * 版本：           
 *
 */
package com.isoftstone.industry.aaa.schedule;

import java.text.ParseException;

import org.apache.log4j.Logger;
import org.springframework.scheduling.quartz.CronTriggerBean;

import com.isoftstone.industry.persistance.bean.BillCycleConfig;
import com.isoftstone.industry.aaa.core.service.assist.IBillCycleConfigService;

/**
 *
 * @author jacky
 */
@SuppressWarnings("serial")
public class AuthorizationCronTrigger extends CronTriggerBean
{
	private final Logger logger = Logger.getLogger(AuthorizationCronTrigger.class);
	
	private IBillCycleConfigService billCycleConfigService;

	public IBillCycleConfigService getBillCycleConfigService()
	{
		return billCycleConfigService;
	}

	public void setBillCycleConfigService(IBillCycleConfigService billCycleConfigService)
	{
		this.billCycleConfigService = billCycleConfigService;
		String cronExpression = getNewCronExpression();
		try
		{
			setCronExpression(cronExpression);
			logger.info("为AuthorizationCronTrigger设置CronExpression:"+cronExpression);
		} catch (ParseException e)
		{
			logger.error(e.getMessage(), e);
		}
	}
	
	 private String getNewCronExpression(){
		 BillCycleConfig config = this.billCycleConfigService.getSystemDefaultCycleConfig();
		 int interval = config.getStartDay()+config.getDurationDay()+config.getDueDurationDays();
		 String cronExpression = "0 1 0 "+ interval+" * ?";
		 return cronExpression;
	 }
}
